﻿Namespace Converter

    Public Class GroupToImageConverter
        Implements IValueConverter

        Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert

            If parameter Is Nothing Then
                Return DependencyProperty.UnsetValue
            End If

            If Not [Enum].IsDefined(value.GetType, value) Then
                Return DependencyProperty.UnsetValue
            End If

            Dim groupValue = DirectCast([Enum].Parse(value.GetType, CStr(parameter)), Grouping.ProgramGroup)
            Dim imageUri As Uri

            If groupValue = DirectCast(value, Grouping.ProgramGroup) Then
                imageUri = New Uri("pack://application:,,,/NamaAlert;component/Images/ui-radio-button.png")
            Else
                imageUri = New Uri("pack://application:,,,/NamaAlert;component/Images/ui-radio-button-uncheck.png")
            End If

            Return New BitmapImage(imageUri)

        End Function

        Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
            Throw New NotSupportedException
        End Function
    End Class

End Namespace
